package com.sy.servlet;

import com.sy.service.CarService;
import com.sy.service.impl.CarServiceImpl;
import com.sy.vo.CarSearchParams;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;

@WebServlet("/cars/*")
public class CarServlet extends AbstractBaseServlet {
    private CarService carService = new CarServiceImpl();

    @Override
    public Object doService(String action, HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException {
        //如果是根据条件查询车辆
        if ("searchByConditions".equals(action)) {
            CarSearchParams carSearchParams = paramMap2Bean(req, CarSearchParams.class);
            return carService.getCarsByConditions(carSearchParams);
        }
        return null;
    }
}
